/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import dao.EvenementDAO;
import dao.GuichetDAO;
import dao.KitDAO;
import entity.Evenement;
import entity.Guichet;
import entity.Kit;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.jboss.weld.context.ejb.Ejb;


@ManagedBean(name = "kitBean")
@SessionScoped
public class KitBean {
    @Ejb
    KitDAO kitDAO = new KitDAO();
    @Ejb
    EvenementDAO evenementDAO = new EvenementDAO();
    FacesContext context = FacesContext.getCurrentInstance();
    guichetBean bean = (guichetBean) context.getApplication().evaluateExpressionGet(context, "#{guichetBean}", guichetBean.class);
    Guichet guichet = new GuichetDAO().findById(bean.getUser().getId());
    List<Evenement> evenements;
    List<Kit> kits;
    Kit  selectedKit;

    public Kit getSelectedKit() {
        return selectedKit;
    }

    public void setSelectedKit(Kit selectedKit) {
        this.selectedKit = selectedKit;
    }
    
    public KitBean() {
    }

    public Guichet getGuichet() {
        return guichet;
    }

    public void setGuichet(Guichet guichet) {
        this.guichet = guichet;
    }

    public List<Evenement> getEvenements() {
        String[] events=selectedKit.getIdsSpec().split(";");
        List<Evenement> e=new ArrayList<Evenement>();
        for (int i = 0; i < events.length; i++) {
            e.add(evenementDAO.findById(Integer.parseInt(events[i])));
        }
        return e;
    }

    public void setEvenements(List<Evenement> evenements) {
        this.evenements = evenements;
    }

    
    public List<Kit> getKits() {
        return kitDAO.findByProperty("guichet", guichet);
    }

    public void setKits(List<Kit> kits) {
        this.kits = kits;
    }
    
    
}
